# big program test, should test if many symbols fit into the symbol table, if
# big addresses in bytecode are handled well etc.

1
++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ --
++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ --
++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ --
++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ --
++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ --
++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ --
++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ -- ++ --
^

# push many constants and pop them
1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1 0 1 2 3 4
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 

1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1 0 1 2 3 4
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 

# create a few pointers:
~testVarA ~testVarB ~testVarC ~testVarD ~testVarE ~testVarF ~testVarG
~testVarH ~testVarI ~testVarJ ~testVarK ~testVarL ~testVarM ~testVarN
~testVarO ~testVarP ~testVarQ ~testVarR ~testVarS ~testVarT ~testVarU
~testVarV ~testVarW ~testVarX ~testVarY ~testVarZ

~bigVar:1000

999 @'
  $>bigVar
  300 $:bigVar
  --
.
^

# create a few functions:
testFuncA: $testVarA + .
testFuncB: $testVarB + .
testFuncC: $testVarC + .
testFuncD: $testVarD + .
testFuncE: $testVarE + .
testFuncF: $testVarF + .
testFuncG: $testVarG + .
testFuncH: $testVarH + .
testFuncI: $testVarI + .
testFuncJ: $testVarJ + .
testFuncK: $testVarK + .
testFuncL: $testVarL + .
testFuncM: $testVarM + .
testFuncN: $testVarN + .
testFuncO: $testVarO + .
testFuncP: $testVarP + .
testFuncQ: $testVarQ + .
testFuncR: $testVarR + .
testFuncS: $testVarS + .
testFuncT: $testVarT + .
testFuncU: $testVarU + .
testFuncV: $testVarV + .
testFuncW: $testVarW + .
testFuncX: $testVarX + .
testFuncY: $testVarY + .
testFuncZ: $testVarZ + .

# random comment random comment random comment random comment random comment #
# random comment random comment random comment random comment random comment #
# random comment random comment random comment random comment random comment #
# random comment random comment random comment random comment random comment #
# random comment random comment random comment random comment random comment #
# random comment random comment random comment random comment random comment #
# random comment random comment random comment random comment random comment #
# random comment random comment random comment random comment random comment #
# random comment random comment random comment random comment random comment #
# random comment random comment random comment random comment random comment #
# random comment random comment random comment random comment random comment #
# random comment random comment random comment random comment random comment #
# random comment random comment random comment random comment random comment #

testChainFunc:
  10
  testFuncA testFuncB testFuncC testFuncD testFuncE testFuncF testFuncG
  testFuncH testFuncI testFuncJ testFuncK testFuncL testFuncM testFuncN
  testFuncO testFuncP testFuncQ testFuncR testFuncS testFuncT testFuncU
  testFuncV testFuncW testFuncX testFuncY testFuncZ
.

~:randomLabel
~:randomLabel2
~:randomLabel3
~:randomLabel4
~:randomLabel5

testChainFunc # do we survive this?

0 10 "big program" -->

printNum:
  ?'
    $0
    0
    ><

    @' # reverse push the chars
      $0
      10
      %
      "0"
      +
      ><
      10
      /
    .

    ^
    @' # print
      ->
    .
    ^
  ; # zero
    "0" ->
  .

  ^
.

PI: 3216 .

sin:
  1              # stack: x sign

  $1 0 << ?
    ^
    -1 *         # x *= -1
    -1           # sign = -1
  .

  ><             # stack: sign x
  2 PI * %       # x %= 2 * PI

  $0 PI > ?      # x > PI ?
    PI -         # x -= PI
    >< -1 * ><   # sign *= -1
  .

~:randomLabelX

  PI $1 - *      # x *= PI - x

  $0 16 *        # 16 * x
  $1 4 *         # 4 * x
  5 PI * PI *    # 5 * PI * PI
  >< -           # 5 * PI * PI - 4 * x
  1024 /         # (5 * PI * PI - 4 * x) / 1024
  / >< ^ *       # (16 * x) / ((5 * PI * PI - 4 * x) / 1024)
.

factorial:
  ?'
    $0 -- factorial *
  ;
    ^ 1
  .
.

min:
  $1 $1 > ?
    ><
  .

  ^
.

average:
  + 2 /
.

myFunc: # takes 2 nums, just computes some arbitrary expression
  min 10 % factorial 100 average
.

0 "random expression (should be 53): " -->

123 654 myFunc printNum 10 ->

# print "ab"s in a weird way:
100 @'
  $0 2 % ?
    "a" ->
  ;
    "b" ->
  .

  --
.
^

10 ->

~myVar

300 $:myVar

1000 @' # apply sine 1000 times

  $myVar sin $:myVar

  --
.
^

$myVar

0 "sine (should be 222): " --> printNum 10 ->
0 10 "now print 200 in different type envs:" -->

# -------------- ENV 8 ----------------
~8
  ~ptr8_a ~ptr8_b ~ptr8_c ~ptr8_d ~ptr8_e ~ptr8_f ~ptr8_g ~ptr8_h

juggleNumber8:
  $:ptr8_a
  $ptr8_a $:ptr8_b
  $ptr8_b $:ptr8_c
  $ptr8_c $:ptr8_d
  $ptr8_d $:ptr8_e
  $ptr8_e $:ptr8_f
  $ptr8_f $:ptr8_g
  $ptr8_g $:ptr8_h
  $ptr8_h
.

200 juggleNumber8 >0 printNum 10 ->

3 @'
  $ptr8_a=ptr8_b
  ?'
    ?'
      ?'
        ?'
          ?'
            ?'
            0 10 "good" -->
            .
          .
        .
      .
    .
  .
  ^
  --
.
^

@'
  !@ # don't execute the following
   + + + + + + + + + + + + + + + +
   - - - - - - - - - - - - - - - -
   * * * * * * * * * * * * * * * *
   / / / / / / / / / / / / / / / /
.

# ------------- ENV 16 ----------------
~16
  ~ptr16_a ~ptr16_b ~ptr16_c ~ptr16_d ~ptr16_e ~ptr16_f ~ptr16_g ~ptr16_h

juggleNumber16:
  $:ptr16_a
  $ptr16_a $:ptr16_b
  $ptr16_b $:ptr16_c
  $ptr16_c $:ptr16_d
  $ptr16_d $:ptr16_e
  $ptr16_e $:ptr16_f
  $ptr16_f $:ptr16_g
  $ptr16_g $:ptr16_h
  $ptr16_h
.

200 juggleNumber16 >0 printNum 10 ->

3 @'
  $ptr16_a=ptr16_b
  ?'
    ?'
      ?'
        ?'
          ?'
            ?'
            0 10 "good" -->
            .
          .
        .
      .
    .
  .
  ^
  --
.
^

@'
  !@ # don't execute the following
   + + + + + + + + + + + + + + + +
   - - - - - - - - - - - - - - - -
   * * * * * * * * * * * * * * * *
   / / / / / / / / / / / / / / / /
.

# ------------- ENV 32 ----------------
~32
  ~ptr32_a ~ptr32_b ~ptr32_c ~ptr32_d ~ptr32_e ~ptr32_f ~ptr32_g ~ptr32_h

juggleNumber32:
  $:ptr32_a
  $ptr32_a $:ptr32_b
  $ptr32_b $:ptr32_c
  $ptr32_c $:ptr32_d
  $ptr32_d $:ptr32_e
  $ptr32_e $:ptr32_f
  $ptr32_f $:ptr32_g
  $ptr32_g $:ptr32_h
  $ptr32_h
.

200 juggleNumber32 >0 printNum 10 ->

3 @'
  $ptr32_a=ptr32_b
  ?'
    ?'
      ?'
        ?'
          ?'
            ?'
            0 10 "good" -->
            .
          .
        .
      .
    .
  .
  ^
  --
.
^

@'
  !@ # don't execute the following
   + + + + + + + + + + + + + + + +
   - - - - - - - - - - - - - - - -
   * * * * * * * * * * * * * * * *
   / / / / / / / / / / / / / / / /

   ??
   ? ? ? ? ? ? . . . . . .
.

# -------------- ENV 0 ----------------
~0

>myEndLabel # skip the following

0 10 "THIS SHOULDN'T BE PRINTED" -->

@
  ?
    1 2 =
    ?
      @
        @
          0 "abcdefghijklmnop" -->
          !.
        .
        !@
      .
      ++
    ;
      7
      @@
        ?'
        ;
          @'
            !@
          .

          !@
        .

        --
      .
      0 = ?'
        3 +
      .
    .
  ;
    ++
    @
      ?
        ++
        ?
          ?
            ++
          .
        .
      .
    
      @
        <-
        ++
      .
    .
  .
.

~:myEndLabel

0 "another random expression (should be 1280): " -->

1 2 + 20 * 30 min ++ ++ ++ ++ -- 11 // 20 + 16 *
3 4 + 12 * 10 min ++ ++ -- ++ -- 12 // 30 + 15 * +
5 6 + 13 * 20 min -- ++ ++ ++ -- 10 // 31 + 14 * +

printNum 10 ->

testChainFunc # try this again
testChainFunc
testChainFunc
testChainFunc
testChainFunc
testChainFunc

functionWeWontCall:
  123456789
  "abcdefghijk"
  // || *
  ?
    @
      ?
        @@
          ?
            factorial
            # >myEndLabel #
          .
        .
      .
    .
  .

  min
  min
  testChainFunc
  factorial
  testFuncA
  testFuncB
  testFuncC
  testFuncD
  testFuncE
  testFuncF
  testFuncG
  testFuncH
  testFuncI
  testFuncJ
  testFuncK
  average
.

0 10 "print some letters:" -->

#------------- ENV 8 --------------
~8

64 # print 64 "a"s
@@
  "a"
  ><
  --
  ?'
  ;
    !@
  .
.
^

64 # pop them
@@
  ><
  ->
  --
  ?'
  ;
    !@
  .
.
^

10 ->

#------------- ENV 16 -------------
~16

64 # print 64 "a"s
@@
  "a"
  ><
  --
  ?'
  ;
    !@
  .
.
^

64 # pop them
@@
  ><
  ->
  --
  ?'
  ;
    !@
  .
.
^

10 ->

#------------- ENV 32 -------------
~32

1 ^ 2 ^ 3 ^ # just push and pop
4 ^ 5 ^ 6 ^
7 ^ 8 ^ 9 ^

64 # print 64 "a"s
@@
  "a"
  ><
  --
  ?'
  ;
    !@
  .
.
^

64 # pop them
@@
  ><
  ->
  --
  ?'
  ;
    !@
  .
.
^

10 ->

#------------- ENV 0 --------------
~0

# some weird expression
+xf +b011 - * 11 / -d02 // 50 + -10 4 %% + 1000 >< / -b100 +x3 != + $0 -1 << +
+b111 |! 1 + 0 1 2 ?? +

isPrime:
  $0 1 <=
  ?
    ^ 0
  ;
    $0 2 /

    @@
      $0 1 <=
      ?
        ^ ^ 1 !@
      .

      $1 $1 % 0 =
      ?
        ^ ^ 0 !@
      .

      --
    .
  .
.

# push many constants and pop them
1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1 0 1 2 3 4
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 

1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1 0 1 2 3 4
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 

0 10 "primes from 1000: " -->

1000 @'
  $0 isPrime ?
    $0 printNum " " ->
  .

  --
.

10 ->

0 10 "END" -->

!. # now skip everything else

1  ++ -- * / = + - ?? && || // %% * * * * + + + +
2  ++ -- * / = + - ?? && || // %% * * * * + + + +
3  ++ -- * / = + - ?? && || // %% * * * * + + + +
4  ++ -- * / = + - ?? && || // %% * * * * + + + +
5  ++ -- * / = + - ?? && || // %% * * * * + + + +
6  ++ -- * / = + - ?? && || // %% * * * * + + + +
7  ++ -- * / = + - ?? && || // %% * * * * + + + +
8  ++ -- * / = + - ?? && || // %% * * * * + + + +
9  ++ -- * / = + - ?? && || // %% * * * * + + + +
10 ++ -- * / = + - ?? && || // %% * * * * + + + +
11 ++ -- * / = + - ?? && || // %% * * * * + + + +
12 ++ -- * / = + - ?? && || // %% * * * * + + + +
13 ++ -- * / = + - ?? && || // %% * * * * + + + +
14 ++ -- * / = + - ?? && || // %% * * * * + + + +
15 ++ -- * / = + - ?? && || // %% * * * * + + + +
16 ++ -- * / = + - ?? && || // %% * * * * + + + +
17 ++ -- * / = + - ?? && || // %% * * * * + + + +
18 ++ -- * / = + - ?? && || // %% * * * * + + + +
19 ++ -- * / = + - ?? && || // %% * * * * + + + +
20 ++ -- * / = + - ?? && || // %% * * * * + + + +

+xbeeface
-b10101
9999223
"test"
-101010
"test2"

@
  ?
    ++ --
    !@
    !.
  .

  ?'
    ?
      ++
    .
  .
.

0 10 "THIS SHOULDN'T BE PRINTED" -->
